package main

import "fmt"

func deferUtil() func(int) int {
	i := 0
	return func(n int) int {
		fmt.Printf("本次调用接收到n=%v\n", n)
		i++
		fmt.Printf("匿名工具函数第%v次被调用\n", i)
		return i
	}
}
func Defer() int {
	f := deferUtil()
	//f(1)
	defer f(1)
	//defer f(f(3))
	return f(2)
}

func Defer2() {
	defer func() {
		err := recover()
		if err != nil {
			fmt.Println(err)
		}
	}()
	n := 0
	fmt.Println(3 / n)
}

func maindeffer() {
	Defer()
	Defer2()
}
